<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script src='./socket.io.js'></script>
<script src='./jquery.js'></script>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
</head>
<p id="uid"></p>
<p id='total-users'></p>
<a href="javascript:;" id="request" >发送请求</a>
<script>
// 使用时替换成真实的uid，这里方便演示使用时间戳
var ip = returnCitySN['cip'];
var uid = $('#uid').text( Date.parse(new Date()));
$(document).ready(function () {
    // 连接服务端
    var socket = io('http://127.0.0.1:3324');
    // 连接后登录
    socket.on('connect', function(){
        socket.emit('online', $('#uid').text(),ip);
    });

    // 后端推送来在线数据时
    socket.on('total-users', function(online_stat){
        $('#total-users').text(online_stat);
    });

});


$(document).ready(function () {
    $('#request').on('click',function(){
        $(this).attr('href',"http://127.0.0.1:3726?uid="+$('#uid').text());
        window.location.href = $(this).attr('href');
    });
});

</script>
</body>
</html>
